Introduction
============
This Database Driven File Manager is a simple extension/adaptation of the Image Manager for
HTMLarea and REPLACES the original insert_link.html function. As such, it should not be regarded more than a mod to this useful
add-on. It's built to work together with the Add-On Database Driven Image Inserting and Pure ASP-Upload.
Those Add-On's can be downloaded from http://www.savio.no/htmlarea/example.asp
This download is approx 1,5 Mb.

Functionality
=============
Called from an HTMLarea, File Manager lets you browse for any file in that is stored
as "Document" in the Database. The file will be selected and then a link to this 
file will be inserted in the original textarea with target-value set to blank. Changes in this value is done in filelist.asp

Compatability
=============
This script has been tested with HTMLarea 2.03 only and I cannot give any
guarantees as such. However, with some small adjustments, it should work for
HTMLarea 3.0a too.

Installation
============
Extract the files in the zip-file to the htmlarea/ directory, using
folder names.

In the editor.js file search for "createlink" or "insertlink" and replace that code with the code below:

// insert link (modified)    
    if (cmdID.toLowerCase() == 'insertlink') {
    	var theRange = editdoc.selection.createRange();
    	
    	var highlightedText = "";
	var linkText = '';
    	
    	var href_attribute = '';
    	var tar_attribute = '';
    	
    	var elmSelectedImage;
    	var htmlSelectionControl = "Control";
    	if (editdoc.selection.type == htmlSelectionControl) {
    		// actully we have an image.
    		elmSelectedImage = theRange.item(0);
    		highlightedText = elmSelectedImage.outerHTML;
    		
    		//convert the ControlRange to a TextRange
    		theRange = editdoc.body.createTextRange();
		theRange.moveToElementText(elmSelectedImage);
    		theRange.select();
    		
    		fullElement = theRange.htmlText;
    	} else {
    		if (theRange.text != '') {
    			highlightedText = theRange.htmlText;
    		}
    		fullElement = theRange.parentElement().outerHTML;
	}
	
	//in case we happen to select the link itself!
	if (highlightedText.search(/^\<[A|a]/) != -1) {
		fullElement = highlightedText;
	}
	
	//extrect attributes from HTML
	if (fullElement.search(/^\<[A|a]/) != -1) {

		fullElement = fullElement.replace(/\"/g, "");
		fullElement = fullElement.replace(/\'/g, "");

		// here, we have an <a> tag. Now let's extract... 
		// 1. the href attribute
		var href_value = fullElement.split(/href=/);
		href_value2 = href_value[1].split(/\s|>/);
		href_attribute = href_value2[0];

		// 2. the target attribute
		if (fullElement.search(/target=/) != -1) {
			var tar = fullElement.split(/target=/);
			tar2 = tar[1].split(/\s|>/);
			tar_attribute = tar2[0];
		}

		// 3. the link text (more robust as includes all html code aswell)
		pos1 = fullElement.indexOf(">");
		pos2 = fullElement.lastIndexOf("<");
		linkText = fullElement.substring(pos1+1,pos2);
	}
    	
    	var myValues = new Object();
    	myValues.highlightedText = highlightedText;
    	myValues.tar_attribute = tar_attribute;
    	myValues.href_attribute = href_attribute;
    	myValues.linkText = linkText;
    
    	var myText = showModalDialog(_editor_url + "popups/insert_file.html", myValues, "status=no; scroll=no");
    
    	if (linkText != '') { 
    		if (myText) { 
    			theRange.parentElement().outerHTML = '';
    			editor_insertHTML(objname, unescape( myText) );
    		}
    	} else {
    		if (myText) { 
    			//if (editdoc.selection.type == htmlSelectionControl) {
    			//	theRange.execCommand('Delete');
    			//}
    			editor_insertHTML(objname, unescape(myText) ); // this function ALWAYS puts in an absolute link 
    		} 
    	}
    
    }
		

All the code mentioned here is for the editor.js file.

Customizations
==============
You might want to change what will be passed on to the editor, as well as the
format of the output. Feel free to modify what ever you wan't. 
Since I'm not that good with JS there can be lot's of things to improve that I don't know about.
The( ASP)-coding in the filelist.asp file is messy. You probably wan't to clean it up.
Made with Dreamweaver MX so...

About the adaptor
=================
Eivind Savio <http://www.savio.no>

